package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author fallrain
 * @Description 通过线程池创建线程
 * @Date 2022/2/11 9:20
 * @Version 1.0
 */
public class ThreadPool implements Runnable{

    private static int POOL_NUM = 10;     //线程池数量


    @Override
    public void run() {
        System.out.println("通过线程池方式创建的线程：" + Thread.currentThread().getName() + " ");
    }

    public static void main(String[] args) throws InterruptedException{
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 0; i < POOL_NUM; i++){
            ThreadPool threadPool = new ThreadPool();
            executorService.execute(threadPool);
        }
        executorService.shutdown();
    }
}
